const util = require('./util.js')
const baseurl = util.baseurl

export { getRegionTree,getSubRegion };
// 获取区域树
const getRegionTree = () => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        wx.request({
            url: baseurl + '/Region/GetRegionTree',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
// 查询子区域
const getSubRegion = (fatherId) => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        wx.request({
            url: baseurl + '/Region/GetRegionsByFatherId',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            data: {
                fatherId: fatherId
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
